package cn.edu.sjtu.se.dslab.rhapsody.entity;

import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;

public class Task {
	public static final Logger LOG = Logger.getLogger(Task.class);
	
	private int taskIndex;
	private String name;
	private int rate = 25;
	private int priority = 180;
	private int stackSize = 10240;
	private String taskType;
	
	private List<Agent> agents;
	
	public Task(int taskIndex){
		this.taskIndex = taskIndex;
		taskType = "SFTaskTypeSoft";
		agents = new ArrayList<Agent>();
	}
	
	public String getInitMethodName(){
		StringBuilder initMethod = new StringBuilder();
		initMethod.append("task").append(taskIndex).append("Init");
		return initMethod.toString();
	}
	
	public String getWorkMethodName(){
		StringBuilder workMethod = new StringBuilder();
		workMethod.append("task").append(taskIndex).append("Work");
		return workMethod.toString();
	}
	
	public String getTaskAddName(){
		StringBuilder taskAdd = new StringBuilder("SFAppAddTask(");
		taskAdd.append(taskType).append(", \"").append(name).append("\", ")
			.append(rate).append(", ").append(priority).append(", ")
			.append(stackSize).append(", ")
			.append(getInitMethodName()).append(", ")
			.append(getWorkMethodName()).append("); ");
		LOG.info("TaskAdd function = " + taskAdd.toString());
		return taskAdd.toString();
	}
	
	public List<Agent> getAgents() {
		return agents;
	}

	public void setAgents(List<Agent> agents) {
		this.agents = agents;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getRate() {
		return rate;
	}

	public void setRate(int rate) {
		this.rate = rate;
	}

	public int getPriority() {
		return priority;
	}

	public void setPriority(int priority) {
		this.priority = priority;
	}

	public int getStackSize() {
		return stackSize;
	}

	public void setStackSize(int stackSize) {
		this.stackSize = stackSize;
	}

	public String getTaskType() {
		return taskType;
	}

	public void setTaskType(String taskType) {
		this.taskType = taskType;
	}

	public int getTaskIndex() {
		return taskIndex;
	}
	
	public void addAgent(Agent agent){
		agents.add(agent);
	}
	
	
}
